/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.common.util.AccountLogger;
/*     */ import com.zimbra.common.util.Log.Level;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.soap.SoapProvisioning;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestLog
/*     */   extends TestCase
/*     */ {
/*     */   public void setUp()
/*     */     throws Exception
/*     */   {
/*  34 */     cleanUp();
/*     */   }
/*     */   
/*     */   public void testAccountLoggers() throws Exception
/*     */   {
/*  39 */     SoapProvisioning prov = TestUtil.newSoapProvisioning();
/*  40 */     Account user1 = TestUtil.getAccount("user1");
/*  41 */     Account user2 = TestUtil.getAccount("user2");
/*  42 */     Account user3 = TestUtil.getAccount("user3");
/*  43 */     Account user4 = TestUtil.getAccount("user4");
/*     */     
/*     */ 
/*  46 */     List<AccountLogger> loggers = prov.addAccountLogger(user1, "zimbra.filter", "debug", null);
/*  47 */     assertLoggerExists(loggers, user1, "zimbra.filter", Log.Level.debug);
/*  48 */     loggers = prov.addAccountLogger(user2, "zimbra.backup", "info", null);
/*  49 */     assertLoggerExists(loggers, user2, "zimbra.backup", Log.Level.info);
/*  50 */     loggers = prov.addAccountLogger(user3, "zimbra.sync", "warn", null);
/*  51 */     assertLoggerExists(loggers, user3, "zimbra.sync", Log.Level.warn);
/*  52 */     loggers = prov.addAccountLogger(user3, "zimbra.lmtp", "warn", null);
/*  53 */     assertLoggerExists(loggers, user3, "zimbra.lmtp", Log.Level.warn);
/*  54 */     assertEquals(1, loggers.size());
/*  55 */     loggers = prov.addAccountLogger(user4, "zimbra.lmtp", "error", null);
/*  56 */     assertLoggerExists(loggers, user4, "zimbra.lmtp", Log.Level.error);
/*     */     
/*     */ 
/*  59 */     loggers = prov.getAccountLoggers(user1, null);
/*  60 */     assertEquals(1, loggers.size());
/*  61 */     assertLoggerExists(loggers, user1, "zimbra.filter", Log.Level.debug);
/*     */     
/*  63 */     loggers = prov.getAccountLoggers(user2, null);
/*  64 */     assertEquals(1, loggers.size());
/*  65 */     assertLoggerExists(loggers, user2, "zimbra.backup", Log.Level.info);
/*     */     
/*  67 */     loggers = prov.getAccountLoggers(user3, null);
/*  68 */     assertEquals(2, loggers.size());
/*  69 */     assertLoggerExists(loggers, user3, "zimbra.sync", Log.Level.warn);
/*  70 */     assertLoggerExists(loggers, user3, "zimbra.lmtp", Log.Level.warn);
/*     */     
/*  72 */     loggers = prov.getAccountLoggers(user4, null);
/*  73 */     assertEquals(1, loggers.size());
/*  74 */     assertLoggerExists(loggers, user4, "zimbra.lmtp", Log.Level.error);
/*     */     
/*     */ 
/*  77 */     prov.removeAccountLoggers(user1, "zimbra.filter", null);
/*  78 */     prov.removeAccountLoggers(user2, null, null);
/*  79 */     prov.removeAccountLoggers(user4, null, null);
/*     */     
/*     */ 
/*  82 */     Map<String, List<AccountLogger>> map = prov.getAllAccountLoggers(null);
/*  83 */     assertEquals(1, map.size());
/*  84 */     loggers = (List)map.get(user3.getName());
/*  85 */     assertEquals(2, loggers.size());
/*  86 */     assertLoggerExists(loggers, user3, "zimbra.sync", Log.Level.warn);
/*  87 */     assertLoggerExists(loggers, user3, "zimbra.lmtp", Log.Level.warn);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public void testAllCategories()
/*     */     throws Exception
/*     */   {
/*  96 */     SoapProvisioning prov = TestUtil.newSoapProvisioning();
/*  97 */     Account account = TestUtil.getAccount("user1");
/*  98 */     assertEquals(0, prov.getAccountLoggers(account, null).size());
/*  99 */     List<AccountLogger> loggers = prov.addAccountLogger(account, "all", "debug", null);
/* 100 */     assertTrue(loggers.size() > 1);
/*     */     
/*     */ 
/* 103 */     assertLoggerExists(loggers, account, "zimbra.soap", Log.Level.debug);
/* 104 */     loggers = prov.getAccountLoggers(account, null);
/* 105 */     assertLoggerExists(loggers, account, "zimbra.soap", Log.Level.debug);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public void testRemoveAll()
/*     */     throws Exception
/*     */   {
/* 113 */     SoapProvisioning prov = TestUtil.newSoapProvisioning();
/* 114 */     Account user1 = TestUtil.getAccount("user1");
/* 115 */     Account user2 = TestUtil.getAccount("user2");
/*     */     
/* 117 */     prov.addAccountLogger(user1, "zimbra.soap", "debug", null);
/* 118 */     prov.addAccountLogger(user1, "zimbra.sync", "debug", null);
/* 119 */     prov.addAccountLogger(user2, "zimbra.soap", "debug", null);
/* 120 */     prov.addAccountLogger(user2, "zimbra.sync", "debug", null);
/*     */     
/*     */ 
/* 123 */     List<AccountLogger> loggers = prov.getAccountLoggers(user1, null);
/* 124 */     assertEquals(2, loggers.size());
/* 125 */     prov.removeAccountLoggers(user1, null, null);
/* 126 */     loggers = prov.getAccountLoggers(user1, null);
/* 127 */     assertEquals(0, loggers.size());
/*     */     
/*     */ 
/* 130 */     loggers = prov.getAccountLoggers(user2, null);
/* 131 */     assertEquals(2, loggers.size());
/* 132 */     prov.removeAccountLoggers(user2, "all", null);
/* 133 */     loggers = prov.getAccountLoggers(user2, null);
/* 134 */     assertEquals(0, loggers.size());
/*     */   }
/*     */   
/*     */   private void assertLoggerExists(Iterable<AccountLogger> loggers, Account account, String category, Log.Level level) {
/* 138 */     for (AccountLogger logger : loggers) {
/* 139 */       if ((logger.getAccountName().equals(account.getName())) && (logger.getCategory().equals(category))) {
/* 140 */         assertEquals(level, logger.getLevel());
/* 141 */         return;
/*     */       }
/*     */     }
/* 144 */     fail("Could not find logger for account " + account.getName() + ", category " + category);
/*     */   }
/*     */   
/*     */   public void tearDown() throws Exception
/*     */   {
/* 149 */     cleanUp();
/*     */   }
/*     */   
/*     */   private void cleanUp() throws Exception
/*     */   {
/* 154 */     TestUtil.newSoapProvisioning().removeAccountLoggers(null, null, null);
/*     */   }
/*     */   
/*     */   public static void main(String[] args) throws Exception
/*     */   {
/* 159 */     TestUtil.cliSetup();
/* 160 */     TestUtil.runTest(TestLog.class);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestLog.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */